package util;




import java.sql.Connection;  
import java.sql.DriverManager;  
 
import java.sql.SQLException;  
import javax.swing.JOptionPane;

public class DUBtil {

	public Connection getConnection() {
	Connection con=null;	
		try {
			Class.forName("org.gjt.mm.mysql.Driver");
			con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sellthings?useUnicode=true&characterEncoding=utf-8","root","root");//�������ݿ�����
			return con;
		} catch (ClassNotFoundException e) {
			JOptionPane.showMessageDialog(null, "数据库驱动程序找不到!","警告", 0);
			return null;
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "数据库连接失败!","警告", 0);
			return null;
	}

	}
	
	public void close(Connection con){
		if(con!=null){
			try {
				con.close();
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, "数据库关闭失败!","警告", 0);
			}
		}
	}
	
}
